package com.xdd.util;

import java.io.*;

/**
 * @author XDD
 * @project reptile-demo
 * @date 2020/4/20
 * @description Good Good Study,Day Day Up.
 */
public class FileUtils {


    public static boolean saveFile(String savePath, InputStream inputStream) throws IOException {
        if(savePath==null || inputStream==null){
            return false;
        }
        if(inputStream.available()<=1){
            return false;
        }
        File file = new File(savePath);
        if(file.getParentFile()==null || !file.getParentFile().isDirectory()){
            file.getParentFile().mkdirs();
        }
        FileOutputStream fos = new FileOutputStream(file);

        byte[] bytes = new byte[2048];
        int flag = 0;
        while ((flag=inputStream.read(bytes))!=-1){
            fos.write(bytes,0,flag);
        }
        fos.flush();
        fos.close();
        inputStream.close();
        return true;
    }
}
